package com.souku.finance.application.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.souku.finance.application.R;
import com.souku.finance.application.utils.MyTextUtil;
import com.souku.finance.application.widget.MyTextView;

/**
 * Created by Android on 2017/1/16.
 */

public class PayInfoDialog extends Dialog implements View.OnClickListener {

    protected View rootView;
    protected MyTextView tvMoney;
    protected MyTextView tvBalance;
    protected MyTextView tvRed;
    protected RelativeLayout relativeRed;
    protected TextView tvCardName;
    protected TextView tvCardNo;
    protected MyTextView tvCard;
    protected Button btnPay;
    private String money;
    private String balance;
    private String red;
    private String card;
    private View.OnClickListener listener;

    public PayInfoDialog(Context context, String money, String balance, String red, String card, View.OnClickListener listener) {
        super(context, R.style.myDialogFullNo);
        this.money = money;
        this.balance = balance;
        this.red = red;
        this.card = card;
        this.listener = listener;
    }

    public PayInfoDialog(Context context, int themeResId) {
        super(context, themeResId);
    }

    protected PayInfoDialog(Context context, boolean cancelable, OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_payinfo);
        initView();
        if (red == null) {
            relativeRed.setVisibility(View.GONE);
        } else {
            relativeRed.setVisibility(View.VISIBLE);
            tvRed.setText(MyTextUtil.doubleFormat(Double.parseDouble(red)));
        }
        tvCard.setText(MyTextUtil.doubleFormat(Double.parseDouble(card)));
        tvBalance.setText(MyTextUtil.doubleFormat(Double.parseDouble(balance)));
        tvMoney.setText(MyTextUtil.doubleFormat(Double.parseDouble(money)));
    }

    @Override
    public void show() {
        super.show();
        /**
         * 设置宽度全屏，要设置在show的后面
         */
        WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
        layoutParams.gravity = Gravity.CENTER;
        layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
        layoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
        getWindow().getDecorView().setPadding(0, 0, 0, 0);
        getWindow().setAttributes(layoutParams);
    }

    @Override
    public void onClick(View view) {
        if (view.getId() == R.id.btn_pay) {
            listener.onClick(view);
        }
    }

    private void initView() {
        tvMoney = (MyTextView) findViewById(R.id.tv_money);
        tvBalance = (MyTextView) findViewById(R.id.tv_balance);
        tvRed = (MyTextView) findViewById(R.id.tv_red);
        relativeRed = (RelativeLayout) findViewById(R.id.relative_red);
        tvCardName = (TextView) findViewById(R.id.tv_cardName);
        tvCardNo = (TextView) findViewById(R.id.tv_cardNo);
        tvCard = (MyTextView) findViewById(R.id.tv_card);
        btnPay = (Button) findViewById(R.id.btn_pay);
        btnPay.setOnClickListener(PayInfoDialog.this);
    }
}
